package com.forestar.mapControl.utils.mapConvert.task;

import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;

import com.forestar.mapControl.mapview.CacheCanvas;
import com.forestar.mapControl.utils.LogD;

import java.math.BigDecimal;

import static com.forestar.mapControl.utils.mapConvert.task.DrawForTask.heightScreen;
import static com.forestar.mapControl.utils.mapConvert.task.DrawForTask.offsetNum;
import static com.forestar.mapControl.utils.mapConvert.task.DrawForTask.offsetNumY;
import static com.forestar.mapControl.utils.mapConvert.task.DrawForTask.tileSizeForShow;
import static com.forestar.mapControl.utils.mapConvert.task.DrawForTask.widthScreen;

/**
 * created by  xzk
 * 2020/8/6   20:42
 * 说明:
 */
public class DrawTestHelper {

    private LoadTileCommonTask loadFileTileTask ;

//------------------- 以下 1用来画bitmap，，，0用来画0，，，屏幕来画0           ------------------------

//    protected Paint boxPaint = new Paint();
//    protected Rect screenBox = new Rect(-800,-1280,2400,3840);
//
//    //第二个画布，用来画图片
//    private Runnable canvasDraw2 = new Runnable() {
//
//        Paint temppaint = new Paint();
//        private void drawForCache(){
//            int width = DrawForTask.widthScreen;
//            int height = DrawForTask.heightScreen;
//            Rect dstCanvasRect = new Rect(0,0,width,height);
//            CacheCanvas cacheCanvas0 = cacheCanvasList.get(0);
//            CacheCanvas cacheCanvas1 = cacheCanvasList.get(1);
//            //加锁，控制一次加载到缓存的数量，避免混乱
//            synchronized (cacheCanvas0.lockObject){
//                cacheCanvas0.getCanvas().drawBitmap(cacheCanvas1.getBitmap(), null, dstCanvasRect, temppaint);
//            }
//            if(refreshListener != null){
//                refreshListener.onRefresh();
//            }
//        }
//
//        @Override
//        public synchronized void run() {
//            boxPaint.setColor(Color.RED);
//            boxPaint.setStyle(Paint.Style.STROKE);
//            boxPaint.setStrokeWidth(2);
//
//            long startNormal = System.currentTimeMillis();
//            long startForCanvasMill = startNormal;
//            long endForCanvasMill =0;
//            CacheCanvas cacheCanvas1 = cacheCanvasList.get(1);
//
//            float distanceX = transformNew.getDistanceX();
//            float distanceY = transformNew.getDistanceY();
////            cacheCanvas.getCanvas().translate(distanceX,distanceY);
//
//            int startX=new BigDecimal(-((float)(widthScreen/2))-distanceX).intValue();
//            int startY=new BigDecimal(-((float)(heightScreen/2))-distanceY).intValue();
//            //计算一个屏幕需要多少张瓦片  上下左右
//            offsetNum = widthScreen*2/tileSizeForShow;
//            offsetNumY = heightScreen*2/tileSizeForShow;
//            LogD.d("一共需要多少张瓦片:"+offsetNum+"x"+offsetNumY+"="+(offsetNum*offsetNumY));
//
//            if(startX>1500){
//                startX = 1500;
//            }else if(startX<-800){
//                startX = -800;
//            }
//            if(startY>2500){
//                startY = 2500;
//            }else if(startY<-1280){
//                startY = -1280;
//            }
//            Rect rect = new Rect(startX,startY,startX+tileSizeForShow,startY+tileSizeForShow);
//            LogD.d("偏移距离："+distanceX+":绘制到区域:"+rect);
//            int i= 1-offsetNum;
//
//            int allNum = 0;
//
//            cacheCanvas1.getCanvas().drawColor(Color.parseColor("#FFFAFA"));
//            //总共1层
//            for (int j = 0; j < bitmapTempList.size(); j++) {
//                endForCanvasMill = System.currentTimeMillis();
//                long diffTime = endForCanvasMill - startForCanvasMill;
//                if(diffTime>80){
//                    LogD.d("计时："+diffTime);
//                    drawForCache();
//                    startForCanvasMill = endForCanvasMill;
//                }
//                Bitmap bitmap = bitmapTempList.get(j);
//                if (null == bitmap || bitmap.isRecycled()) {
//                    continue;
//                }
//                if(startForCanvasMill<1){
//                    startForCanvasMill = System.currentTimeMillis();
//                }
//                cacheCanvas1.getCanvas().drawBitmap(bitmap, null, rect, tempPaint);
//                cacheCanvas1.getCanvas().drawRect(rect.left, rect.top, rect.right, rect.bottom, boxPaint);
//                allNum++;
//
//                //在当前图层绘制
//                if (i % offsetNum != 0) {
//                    rect.left = rect.left + tileSizeForShow;
//                    rect.right = rect.right + tileSizeForShow;
//                    rect.top = rect.top;
//                    rect.bottom = rect.bottom;
//                } else {
//                    rect.left = startX;
//                    rect.right = startX+tileSizeForShow;
//                    rect.top = rect.top + tileSizeForShow;
//                    rect.bottom = rect.bottom + tileSizeForShow;
//                }
//                i++;
//            }
//            long endNormal = System.currentTimeMillis();
//            LogD.d("本次从图片绘制到一层缓存："+allNum+"<--耗时-->"+(endNormal-startNormal));
//            //绘制完成之后，再绘制一遍
//            //减少1
////            hasTaskNum.decrementAndGet();
//            drawForCache();
//        }
//    };
////------------------- 以上  1用来画bitmap，，，0用来画0，，，屏幕来画0          ------------------------

}
